import { preResAttributeLoad } from "./traverse";
import { ResourceVal } from "../typings/utils";
/**
 *
 * @param val
 * 将attr[1]解析为attr.1同时将1返回
 */
export function parseResourceVal(_val: string) {
  let val: string = preResAttributeLoad(_val);
  let checked: undefined | number;
  let valItems = val.split(".");
  if (valItems.length == 2) {
    checked = Number(valItems.pop());
    val = String(valItems.pop());
    if (!Number.isInteger(checked)) {
      checked = undefined;
    }
  }
  let resourceVal: ResourceVal = {
      val,
      checked
  }
  return resourceVal;
}
